
$(function(){
	var thisPokerClass=$(".pokerClass").first();//当前选择牌型
	var pokerGroup;//牌组
	$(".pokerClass").on("click",function(){
		$(this).siblings(".pokerClass").removeClass("btn-success").addClass("btn-primary");
		$(this).addClass("btn-success");
		thisPokerClass=$(this);
	});
	
	$(".poker").on("click",function(){
		if($(this).data("disabled")){
			return;
		}
		var dataPoker=thisPokerClass.data("dataPoker");
		if(dataPoker!=null){
			if(dataPoker.length<13){
				thisPokerClass.data("dataPoker").push(JSON.parse($(this).attr("evalData")));
				$(this).parent().css("background-color","#000");
				$(this).css("opacity","0.4");
				$(this).data("disabled",true);
				cloneImageInGroup($(this),thisPokerClass);
			}else{
//				dataPoker.sort(function(a,b){
//					return a.indexVal-b.indexVal;
//				});
//				console.log(dataPoker);
				if(thisPokerClass.nextAll(".pokerClass").length<1)
					thisPokerClass=$(".pokerClass").first();
				else
					thisPokerClass.nextAll(".pokerClass").first().trigger("click");
				$(this).trigger("click");
				
				//alert("最多十三张");
			}
		}else{
			thisPokerClass.data("dataPoker",[JSON.parse($(this).attr("evalData"))]);
			$(this).parent().css("background-color","#000");
			$(this).css("opacity","0.4");
			$(this).data("disabled",true);
			cloneImageInGroup($(this),thisPokerClass);
		}
	});
});
function getImageOrder(){
	$.post("../pokermgr/getImageOrderPath",function(data){
		var fangkuai=data["fangkuai"];
	},"json");
}

/**
 * 
 * @param data
 */
function builderImageTag(data){
	var html;
	if(data!=null){
		$(data).foreach(function(obj,i){
			html+="<img />";
		});
	}
}
/**
 *点击后复制扑克到分组 
 */
function cloneImageInGroup(img,thisPokerClass){
	var $img=$("<img class='rePokerImg' ondragstart='return false' onclick='delPoker(this)' src="+img.attr("src")+" style='height:50px;cursor:pointer;'>");
	$img.data("evelData",JSON.parse(img.attr("evalData")));
	thisPokerClass.next().append($img);
}
/**
 * 删除扑克
 * @param el
 */
function delPoker(el){
	if(sys.delFail) return;
	$(".poker[src='"+$(el).attr("src")+"']").css("opacity","1").data("disabled",false);
	$(".poker[src='"+$(el).attr("src")+"']").parent().css("background-color","#fff");
	$($(el).parent().prev(".pokerClass").data("dataPoker")).each(function(i,data){
		if(data["indexVal"]==$(el).data("evelData")["indexVal"]){
			$(el).parent().prev(".pokerClass").data("dataPoker").splice(i,1);
		}
	});
	$(el).remove();
}

function login(){
	var userName=$("#login_userName").val()||'',pwd=$("#login_pwd").val()||'';
	$.ajax({
		type: "POST",
		url:sys.contextPath+"/base/loginData?userName="+userName+"&pwd="+pwd,
		data:{},
		dataType:"json",
		contentType:"application/json",
		success: function(data) {
			if(data && !data.error){
				window.location=sys.contextPath+"/pokermgr/mainPage";
			}else{
				alertify.error(data.msg);
			}
		}
	});
}